package com.qfedu.fmmall.controller;

import com.qfedu.fmmall.service.UserService;
import com.qfedu.fmmall.vo.ResultVO;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
@Api(value = "提供用户的注册和登录接口",tags = "用户管理")
public class UserController {
    @Resource
    private UserService userService;

    @ApiOperation("⽤户登录接⼝")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string",name = "username", value = "⽤户登录账号",required = true),
            @ApiImplicitParam(dataType = "string",name = "password", value = "⽤户登录密码",required = true)
    })
    @GetMapping("/login")
    public ResultVO login(@RequestParam("username") String name,
                          @RequestParam(value = "password") String pwd){
        ResultVO resultVO = userService.checkLogin(name, pwd);
        return resultVO;
    }
    @ApiOperation("⽤户注册接⼝")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string",name = "username", value = "⽤户注册账号",required = true),
            @ApiImplicitParam(dataType = "string",name = "password", value = "⽤户注册密码",required = true)
    })
    @PostMapping("/regist")
    public ResultVO regist(String username,String password){
        ResultVO resultVO = userService.userRegist(username, password);
        return resultVO;
    }
}